package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
@Slf4j
public class NursingProjectServiceImpl implements NursingProjectService {

    @Autowired
    private NursingProjectMapper nursingProjectMapper;


    @Override
    public PageResponse<NursingProjectVo> getByPage(String name, Integer status, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        Page<NursingProject> nursingProjects = nursingProjectMapper.getByPage(name,status);
        PageResponse<NursingProjectVo> projectVoPageResponse = PageResponse.of(nursingProjects, NursingProjectVo.class);


        return projectVoPageResponse;
    }

    @Override
    public void addNursingProject(NursingProjectDto nursingProjectDto) {

        NursingProject nursingProject = BeanUtil.toBean(nursingProjectDto, NursingProject.class);

        nursingProjectMapper.addNursingProject(nursingProject);

    }

    @Override
    public NursingProjectVo getNursingProject(Long id) {
        log.info("根据id回显咯，id:{}",id);

    NursingProject nursingProject =   nursingProjectMapper.getNursingProject(id);


        return BeanUtil.toBean(nursingProject,NursingProjectVo.class);
    }

    @Override
    public void updateNursingProject(NursingProjectDto nursingProjectDto) {
           NursingProject nursingProject =new NursingProject();
        BeanUtils.copyProperties(nursingProjectDto, nursingProject);

        nursingProjectMapper.updateNursingProject(nursingProject);




    }
}
